home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / COMMADIO / ODYSSEY.LZH / ODY150SH.LZH / ODYHOST.HSC < prev    next >
Text File  |  1991-09-11  |  12KB  |  450 lines

  1.  
  2. SCRIPT OdyHost;
  3.  
  4. (************************************************************************)
  5. (*                                                                      *)
  6. (*                     Odyssey Host Mode Script                         *)
  7. (*                Copyright (c) Don Milne, July 1990                    *)
  8. (*                                                                      *)
  9. (************************************************************************)
  10.  
  11. VAR DefaultBaudRate:Number;
  12.     GotLeaveCmd,PrivUser,LostCarrier:Flag;
  13.     CurrDir,OrigDir:String;
  14.     FileOK,GotChar,Carrier,AlreadyConnected,Busy:Flag;
  15.     OldCrMode:Number;
  16.  
  17. (* Host mode info, configured in Odyssey by user *)
  18. VAR NormPass,PrivPass,Welcome,HostDir:String;
  19.     MNPwanted:Flag;
  20.  
  21. (*.........................................*)
  22.  
  23. FUNC CarrierLost():Flag;
  24.  
  25. VAR tempcarrier:Flag;
  26.  
  27. BEGIN
  28.      IF LostCarrier THEN RETURN(TRUE) END;
  29.      tempcarrier := OnLine();
  30.      IF (Carrier<>tempcarrier) AND (NOT tempcarrier) THEN
  31.          Delay(1);
  32.          IF NOT OnLine() THEN
  33.              LostCarrier:=TRUE;
  34.              Carrier := FALSE;
  35.              AlreadyConnected := FALSE;
  36.              RETURN TRUE
  37.          END;
  38.      END;
  39.      RETURN FALSE;
  40. END;
  41.  
  42. (*.........................................*)
  43.  
  44. PROC SendString(s:String);
  45. BEGIN
  46.      Write(s); Transmit(s);
  47. END;
  48.  
  49. (*.........................................*)
  50.  
  51. FUNC GetString(VAR s:String; Timout:Number):Flag;
  52. BEGIN
  53.      IF Receive(s,Timout) THEN
  54.          Write(s+"|");
  55.          RETURN TRUE;
  56.      END;
  57.      RETURN FALSE;
  58. END;
  59.  
  60. (*.........................................*)
  61.  
  62. FUNC LeaveHostMode():Flag;
  63. BEGIN
  64.      IF NOT GotLeaveCmd THEN
  65.          WHILE KeyPressed() DO (* leave host mode? *)
  66.              IF RdKey()=27 THEN
  67.                  GotLeaveCmd := TRUE;
  68.              END;
  69.          END;
  70.      END;
  71.      RETURN GotLeaveCmd;
  72. END;
  73.  
  74. (*.........................................*)
  75.  
  76. FUNC GetPassWord():Flag;
  77.  
  78. VAR Attempts:Number;
  79.     GotPassword,Failure:Flag;
  80.     Password:String[20];
  81.  
  82. BEGIN
  83.      PrivUser := FALSE;
  84.      GotPassword := FALSE;
  85.      Failure := FALSE;
  86.      Attempts := 0;
  87.      REPEAT
  88.            SendString("|Enter Password: ");
  89.            Receive(Password,10,NoEcho);
  90.            IF Password = PrivPass THEN
  91.                PrivUser := TRUE;
  92.                GotPassword := TRUE
  93.              ELSIF Password = NormPass THEN
  94.                GotPassword := TRUE
  95.              ELSE
  96.                SendString("Incorrect"); INC(Attempts);
  97.                Failure := (Attempts>=3);
  98.                IF Failure THEN
  99.                    SendString("||Wrong too often.. Byeee|");
  100.                    HangUp();
  101.                END;
  102.            END
  103.      UNTIL GotPassword OR Failure;
  104.      RETURN GotPassword;
  105. END;
  106.  
  107. (*.........................................*)
  108.  
  109. PROC ChangeDirectory();
  110.  
  111. VAR Temp:String;
  112.  
  113. BEGIN
  114.      SendString("|Directory? ");
  115.      IF GetString(Temp,30) THEN
  116.          IF Temp="" THEN RETURN END;
  117.          IF ChDir(Temp) THEN
  118.              CurrDir := Temp
  119.            ELSE
  120.              SendString("No such directory");
  121.              ChDir(CurrDir);
  122.          END;
  123.      END;
  124. END;
  125.  
  126. (*.........................................*)
  127.  
  128. PROC DirectoryListing();
  129.  
  130. VAR Lines,Count,f_attr:Number;
  131.     GotFile:Flag;
  132.     Temp:String;
  133.     Name:String[20];
  134.  
  135. BEGIN
  136.      SendString("Dir Mask? ");
  137.      IF NOT GetString(Temp,30) THEN RETURN END;
  138.      SendString('|');
  139.      IF Temp="" THEN Temp:="*.*" END;
  140.      GotFile := FFirst(Temp,0,Name,f_attr);
  141.      IF GotFile THEN
  142.          Count:=0; Lines:=0;
  143.          WHILE (GotFile) AND (NOT CarrierLost()) DO
  144.              Temp := Name;
  145.              Temp := SubStr(Temp+"              ",0,14);
  146.              SendString(Temp);
  147.              GotFile := FNext(Name,f_attr);
  148.              INC(Count);
  149.              IF Count % 5 = 0 THEN
  150.                  INC(Lines); SendString('|');
  151.                  IF Lines=20 THEN
  152.                      SendString("||More...");
  153.                      GetString(temp,30);
  154.                      IF CarrierLost() THEN RETURN END;
  155.                      SendString('||');
  156.                  END;
  157.              END;
  158.          END;
  159.        ELSE
  160.          SendString("No matching files.|");
  161.      END;
  162.      SendString('||');
  163. END;
  164.  
  165. (*................................................*)
  166.  
  167. FUNC GetFilename(VAR Filename:String; MustExist:Flag):Flag;
  168. BEGIN
  169.      SendString("|Filename? ");
  170.      IF NOT GetString(Filename,30) THEN
  171.          SendString('|');
  172.        ELSE
  173.          IF (Length(Filename)>12) OR (Pos(":",Filename)>=0) OR (Pos("\",Filename)>=0) THEN
  174.              (* for security reasons, path and drive names are not allowed *)
  175.              SendString("|Bad File name|");
  176.              RETURN FALSE;
  177.          END;
  178.          IF IsFile(Filename) THEN
  179.              IF MustExist THEN
  180.                  RETURN TRUE
  181.                ELSE
  182.                  SendString("|Filename used already - pick another!|");
  183.              END;
  184.            ELSIF MustExist THEN
  185.              SendString("|File not found.|");
  186.            ELSE
  187.              RETURN TRUE
  188.          END;
  189.      END;
  190.      RETURN FALSE;
  191. END;
  192.  
  193. (*................................................*)
  194.  
  195. FUNC GetFTMethod(AsciiOK:Flag):Number;
  196.  
  197. VAR c:String[2];
  198.     x:Number;
  199.  
  200. BEGIN
  201.      SendString("Choose method=>|");
  202.      IF AsciiOK THEN SendString("A(scii|") END;
  203.      SendString("X(modem|W(xmodem|Y(modem|B(atch Ymodem|K(ermit|Z(modem|?");
  204.      REPEAT
  205.            IF NOT GetString(c,30) THEN
  206.                RETURN -1;
  207.              ELSIF c<>"" THEN
  208.                x:=Pos(ToUpper(c),"AXYBWKZ");
  209.              ELSIF CarrierLost() THEN
  210.                RETURN -1;
  211.            END;
  212.      UNTIL ((x=0) AND (AsciiOK)) OR ((x>=1) AND (x<=6));
  213.      RETURN x;
  214. END;
  215.  
  216. (*................................................*)
  217.  
  218. PROC SayProtocol(prot:Number; AddDelay:Flag);
  219. BEGIN
  220.      CASE prot OF
  221.           0:SendString("ASCII");
  222.        |  1:SendString("Xmodem");
  223.        |  2:SendString("Ymodem");
  224.        |  3:SendString("Ymodem Batch");
  225.        |  4:SendString("WXmodem");
  226.        |  5:SendString("Kermit");
  227.        |  6:SendString("Zmodem");
  228.      END;
  229.      SendString(" protocol.|");
  230.      IF AddDelay THEN Delay(5) END;
  231. END;
  232.  
  233. (*................................................*)
  234.  
  235. PROC SayResult();
  236. BEGIN
  237.      SendString("|File Transfer ");
  238.      IF FileOK THEN
  239.          SendString("Complete.|")
  240.        ELSE
  241.          SendString("Failed.|")
  242.      END;
  243. END;
  244.  
  245. (*................................................*)
  246.  
  247. FUNC TransferFile(down:Flag; protocol:Number; FileSpec:String):Flag;
  248. BEGIN
  249.      IF down THEN
  250.          RETURN Download(protocol,FileSpec,ResumeTransfer);
  251.        ELSE
  252.          RETURN Upload(Protocol,FileSpec);
  253.      END;
  254. END;
  255.  
  256. (*................................................*)
  257.  
  258. PROC GetFileFromUser();
  259.  
  260. VAR x:Number;
  261.     Filename:String;
  262.  
  263. BEGIN
  264.      x := GetFTMethod(FALSE);
  265.      IF x<0 THEN RETURN END;
  266.      IF (x=XMODEM) OR (x=WXMODEM) OR (x=YMODEM) THEN
  267.          IF NOT GetFilename(Filename,FALSE) THEN RETURN END;
  268.      END;
  269.      SendString("|Ready to receive file using ");
  270.      SayProtocol(x,FALSE);
  271.      FileOK := TransferFile(TRUE,x,Filename);
  272.      SayResult();
  273. END;
  274.  
  275. (*................................................*)
  276.  
  277. PROC SendFileToUser();
  278.  
  279. VAR x:Number;
  280.     f:File;
  281.     blocks,bytes:String[10];
  282.     Filename:String;
  283.  
  284. BEGIN
  285.      x := GetFTMethod(TRUE);
  286.      IF x<0 THEN RETURN END;
  287.      IF NOT GetFilename(Filename,TRUE) THEN RETURN END;
  288.      FOpen(f,Filename);
  289.      FileSize(f,bytes,blocks);
  290.      FClose(f);
  291.      SendString("|File: "+Filename+"|  "+bytes+" bytes, ("+blocks+" Xmodem blocks).|");
  292.      SendString("About to send file using ");
  293.      SayProtocol(x,TRUE);
  294.      Filename := FQualify(Filename);
  295.      FileOK := TransferFile(FALSE,x,Filename);
  296.      SayResult();
  297. END;
  298.  
  299. (*................................................*)
  300.  
  301. PROC GetMenu();
  302.  
  303. VAR c:String[2];
  304.     x:Number;
  305.  
  306. BEGIN
  307.      REPEAT
  308.            IF CarrierLost() OR LeaveHostMode() THEN RETURN END;
  309.      UNTIL GetString(c,5);
  310.      CASE c OF
  311.  
  312.          "C":IF PrivUser THEN
  313.                  ChangeDirectory();
  314.              END;
  315.        | "S":IF PrivUser THEN
  316.                  HostShell();
  317.              END;
  318.        | "F":DirectoryListing();
  319.        | "U":GetFileFromUser();
  320.        | "D":SendFileToUser();
  321.        | "G":SendString("||Goodbye from Odyssey Host.|Please hang up now!!|");
  322.              Delay(1);
  323.              HangUp();
  324.       ELSE
  325.         IF c<>"" THEN SendString("|Error.|") END;
  326.      END;
  327. END;
  328.  
  329. (*................................................*)
  330.  
  331. PROC DisplayMenu();
  332. BEGIN
  333.      CurrDir := CurrentDir();
  334.      REPEAT
  335.            IF CarrierLost() OR LeaveHostMode() THEN RETURN END;
  336.            IF PrivUser THEN
  337.                SendString("|Directory=> "+CurrDir+"|C(hange dir, S)hell, ");
  338.              ELSE
  339.                SendString('|')
  340.            END;
  341.            SendString("F(iles, U(pload, D(ownload, G(oodbye|? ");
  342.            GetMenu();
  343.      UNTIL FALSE;
  344. END;
  345.  
  346. (*.........................................*)
  347.  
  348. PROC HostSession();
  349.  
  350. VAR done,Ok:Flag;
  351.  
  352. BEGIN
  353.      (* We get here when a carrier is detected *)
  354.      SetHelp("");
  355.      SetHelp(" Odyssey Host Mode:  { Call in Progress } ");
  356.      IF NOT AlreadyConnected THEN
  357.          Delay(1);
  358.          SendString("||ODYSSEY "+OdyVersion()+" HOST MODE||");
  359.          SendString(Welcome);
  360.          Ok := GetPassword();
  361.        ELSE
  362.          Ok := TRUE;
  363.      END;
  364.  
  365.      IF Ok THEN
  366.          done := FALSE;
  367.          REPEAT
  368.                IF CarrierLost() OR LeaveHostMode() THEN
  369.                    done:=TRUE
  370.                  ELSE
  371.                    DisplayMenu();
  372.                END;
  373.          UNTIL done;
  374.      END;
  375.      SetHelp("");
  376. END;
  377.  
  378. (*.........................................*)
  379.  
  380. PROC EnterHostMode();
  381.  
  382. VAR CallResult:Number;
  383.  
  384. BEGIN
  385.      Delay(1); (* wait for any characters to clear *)
  386.      REPEAT
  387.          SetHelp(" Odyssey Host Mode:  { Waiting for Call }     Press Esc to leave host mode.");
  388.          CallResult := WaitForCall();
  389.          IF CallResult=1 THEN (* escape hit *)
  390.              GotLeaveCmd := TRUE;
  391.              RETURN;
  392.            ELSIF CallResult=0 THEN
  393.              Delay(1);
  394.              IF OnLine() THEN
  395.                  LostCarrier := FALSE;
  396.                  Carrier := TRUE;
  397.                  HostSession();
  398.                  Carrier := FALSE;
  399.                  Delay(1);
  400.                  PortInit(DefaultBaudRate,8,None,1);
  401.                  AutoAnswer(TRUE);
  402.                  ChDir(HostDir);
  403.              END;
  404.            ELSE
  405.              RETURN;
  406.          END;
  407.      UNTIL FALSE;
  408. END;
  409.  
  410. (*.........................................*)
  411.  
  412. PROC InitHost();
  413. BEGIN
  414.      Emulate("TTY");
  415.      DefaultBaudRate := DTESpeed();
  416.      AlreadyConnected := OnLine();
  417.      GotLeaveCmd := FALSE;
  418.      CRoutTranslation(CRLF);
  419.      OrigDir := CurrentDir();
  420.      GetHostInfo(NormPass,PrivPass,Welcome,HostDir,MNPwanted);
  421.      IF HostDir="" THEN HostDir:=OrigDir END;
  422.      SetZmodem(FALSE,TRUE,FALSE); (* disable Zmodem auto-receive *)
  423.      SetASCII(0,0,FALSE);
  424.      IF NOT OnLine() THEN AutoAnswer(TRUE) END;
  425.      ChDir(HostDir);
  426. END;
  427.  
  428. (*.........................................*)
  429.  
  430. PROC ShutDown();
  431. BEGIN
  432.      ChDir(OrigDir);
  433.      IF NOT OnLine() THEN AutoAnswer(FALSE) END;
  434.      SetHelp("");
  435.      RestoreDefaults();
  436. END;
  437.  
  438. (*.........................................*)
  439.  
  440. BEGIN
  441.      ClrScr();
  442.      Carrier := OnLine();
  443.      Priority(TRUE);
  444.      CanEscape(FALSE);
  445.      InitHost();
  446.      EnterHostMode();
  447.      ShutDown();
  448. END;
  449.  
  450.